package com.sojpt.boot.controller.business;

import com.jfinal.aop.Before;
import com.jfinal.core.paragetter.Para;
import com.jfinal.kit.Kv;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.SqlPara;
import com.sojpt.boot.controller.business.validator.LkyApplyAddValidator;
import com.sojpt.boot.controller.business.validator.LkyClassAddValidator;
import com.sojpt.boot.intercepter.admin.AdminLoginInterceptor;
import com.sojpt.boot.intercepter.admin.AdminPopedomInterceptor;
import com.sojpt.boot.ui.iview.IViewController;
import com.sojpt.kit.SoJLogKit;
import com.sojpt.model.DicPopedom;
import com.sojpt.model.LkyApplyRecord;
import com.sojpt.model.LkyClass;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * Description: 本类用于逾期申请表(学生管理)
 * Created by SMW on 2020/2/12 20:26
 */
@RestController
@RequestMapping("/admin/apply/")
public class LkyApplyAdminController extends IViewController {

    @GetMapping("list")
    public void list(String uid) {
        LkyApplyRecord lkyApplyRecord  = getModel(LkyApplyRecord.class,"lkyApplyRecord");
        System.out.println("用户id:"+uid);
        SqlPara sqlPara = Db.getSqlPara("lky_apply_record.select", Kv.by("uid",uid));
        Page<Record> page = Db.paginate(pageNumber(), pageSize(), sqlPara);
        renderJson(page) ;

    }

    @Before(LkyApplyAddValidator.class)
    @PostMapping("save")
    public void save() {
        DicPopedom dicPopedom = new DicPopedom();
        dicPopedom.setForwardAction("/admin/apply/save");
        LkyApplyRecord lkyApplyRecord  = getModel(LkyApplyRecord.class,"lkyApplyRecord");
        lkyApplyRecord.setId(UUID.randomUUID().toString().replace("-", ""));
        lkyApplyRecord.setStaute(0);
        lkyApplyRecord.setCreationTime(new Date());
        if(lkyApplyRecord.save()) {
            renderJson(Ret.ok());
            dicPopedom.setPopedomName("添加成功");
        } else {
            renderJson(Ret.fail());
            dicPopedom.setPopedomName("添加失败");
        }
        SoJLogKit.writeLog(this, dicPopedom,getSessionUser());
    }


}
